@ECHO OFF 
PUSHD %~DP0
SET CURDIR=%CD%

IF EXIST %CURDIR%\gdal\NUL (
    PUSHD "%CURDIR%\gdal"
) ELSE IF EXIST %CURDIR%\..\gdal\NUL (
    PUSHD "%CURDIR%\..\gdal"
) ELSE IF EXIST %CURDIR%\..\..\gdal\NUL (
    PUSHD "%CURDIR%\..\..\gdal"
) ELSE IF EXIST %CURDIR%\..\bin\gdal\NUL (
    PUSHD "%CURDIR%\..\bin\gdal"
)
SET GDAL_ROOT=%CD%
POPD
IF EXIST %CURDIR%\python\NUL (
    PUSHD "%CURDIR%\python"
) ELSE IF EXIST %CURDIR%\..\python\NUL (
    PUSHD "%CURDIR%\..\python"
) ELSE IF EXIST %CURDIR%\..\..\python\NUL (
    PUSHD "%CURDIR%\..\..\python"
) ELSE (
    REM SET PYTHONNOUSERSITE=1
    GOTO PYTHONNOUSERSITE
)
SET PYTHONUSERBASE=%CD%
POPD

:PYTHONNOUSERSITE

SET GDAL_API_PROXY=ecw,sid,jp2,j2k,ntf
rem SET GDAL_API_PROXY_CONN_POOL=NO
rem SET GDAL_PAM_PROXY_DIR=%TEMP%
SET GDAL_DATA=%GDAL_ROOT%\share\gdal-data
SET GEOTIFF_CSV=%GDAL_DATA%
SET PROJ_LIB=%GDAL_ROOT%\share\proj
SET GDAL_DRIVER_PATH=%GDAL_ROOT%\bin\plugins

SET PYTHONHOME=C:\Python27\ArcGIS10.2
REM SET PYTHONPATH=%PYTHONHOME%\Lib\lib-tk
REM SET PYTHONPATH=%PYTHONHOME%\Lib\site-packages\win32;%PYTHONHOME%\Lib\site-packages\win32\lib;%PYTHONPATH%
REM SET PYTHONPATH=%PYTHONHOME%\Lib\site-packages\pywin32_system32;%PYTHONHOME%\Lib\site-packages\pythonwin;%PYTHONPATH%
SET PYTHONPATH=%GDAL_ROOT%\bin;%GDAL_ROOT%\lib;%PYTHONPATH%
SET PYTHONPATH=%CURDIR%;%PYTHONPATH%

SET path=
SET path=%WINDIR%;%WINDIR%\system32
PATH=%GDAL_ROOT%\bin;%GDAL_ROOT%\lib\osgeo;%PATH%
PATH=%GDAL_DRIVER_PATH%;%PATH%
PATH=%PYTHONPATH%;%PATH%
PATH=%PYTHONHOME%;%PATH%
PATH=%CURDIR%;%PATH%

SET GDAL_SKIP=
SET _GDAL_SKIP=JP2MrSID JP2OpenJPEG

POPD
